package ru.amse.ilyin.analyzer.impl;

import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

import ru.amse.ilyin.analyzer.AnalyzerException;
import ru.amse.ilyin.analyzer.Entity;
import ru.amse.ilyin.analyzer.Interface;

/**
 * Implementation of {@link Entity} interface.
 *
 * @author Alexander Ilyin
 */
public abstract class EntityImpl implements Entity {
    private final String name;

    private Set<Interface> superinterfaces;
    
    /**
     * Creates an instance of <code>EntityImpl</code> class.
     * 
     * @param name name of this entity
     */
    public EntityImpl(String name) {
        this.name = name;
    }
    
    public String getName() {
        return name;
    }

    public Set<Interface> getSuperinterfaces() throws AnalyzerException {
        return superinterfaces;
    }

    void setSuperinterfaces(Set<Interface> superinterfaces) {
        this.superinterfaces = Collections.unmodifiableSet(
                new HashSet<Interface>(superinterfaces));
    }
    
    @Override
    public boolean equals(Object o) {
        if (!(o instanceof EntityImpl)) {
            return false;
        }
        
        final EntityImpl entity = (EntityImpl) o;
        
        return name.equals(entity.name); 
    }
    
    @Override
    public int hashCode() {
        return name.hashCode();
    }
 
    @Override
    public String toString() {
        return name;
    }
}
